//
//  CoModel.m
//  家校互通
//
//  Created by 姬鑫宇 on 15/4/21.
//  Copyright (c) 2015年 姬鑫宇. All rights reserved.
//

#import "CoModel.h"

static NSString *memberStr = @"http://baidu.com/member/";

@implementation CoModel

+ (NSURLSessionDataTask *)blackboardGetNews:(void (^)(BOOL result,NSArray *array,NSError *error))block withtoken:(NSString *)token clazzId:(NSInteger)clazzId withPageNumber:(NSInteger)pageNumber withPageSize:(NSInteger)pageSize
{
    NSDictionary * dict = @{@"token": token, @"clazzId":@(clazzId), @"pageNumber":@(pageNumber),@"pageSize":@(pageSize)};
    return [[AFAppDotNetAPIClient httpSharedClient] POST:@"blackboard/getNews" parameters:dict success:^(NSURLSessionDataTask * __unused task, id JSON) {
        NSLog(@"%@",task.originalRequest);
        NSArray *response = [JSON valueForKeyPath:@"data"];
        NSMutableArray *array = [[NSMutableArray alloc]initWithCapacity:0];
        long code = [[JSON valueForKeyPath:@"code"] integerValue];
        BOOL result;
        if (code == 10000) {
            result = YES;
            for (NSDictionary *dic in response) {
                BlackBoardModel *model = [[BlackBoardModel alloc]initWithDictionary:dic error:nil];
                [array addObject:model];
            }
        }else
            result = NO;
        
        
        if (block) {
            block(result,array,nil);
        }
    } failure:^(NSURLSessionDataTask *__unused task, NSError *error) {
        if (block) {
            block(NO,nil,error);
        }
    }];
}
+ (NSURLSessionDataTask *)getActivitys:(void (^)(BOOL result,NSMutableArray *arrayList,NSError *error))block withtoken:(NSString *)token clazzId:(NSInteger)clazzId withPageNumber:(NSInteger)pageNumber withPageSize:(NSInteger)pageSize
{
    NSDictionary * dict = @{@"token": [DSFUserInfo shareUserInstance].token, @"clazzId":@([DSFUserInfo shareUserInstance].clazz_user.clazz.id)};
    return [[AFAppDotNetAPIClient httpSharedClient] POST:@"blackboard/getNews" parameters:dict success:^(NSURLSessionDataTask * __unused task, id JSON) {
        NSLog(@"%@",task.originalRequest);
        NSArray *response = [JSON valueForKeyPath:@"data"];
        NSMutableArray *array = [[NSMutableArray alloc]initWithCapacity:0];
        long code = [[JSON valueForKeyPath:@"code"] integerValue];
        BOOL result;
        if (code == 10000) {
            result = YES;
            for (NSDictionary *dic in response) {
                BlackBoardModel *model = [[BlackBoardModel alloc]initWithDictionary:dic error:nil];
                [array addObject:model];
            }
        }else
            result = NO;
        
        
        if (block) {
            block(result,array,nil);
        }
    } failure:^(NSURLSessionDataTask *__unused task, NSError *error) {
        if (block) {
            block(NO,nil,error);
        }
    }];
}
+ (NSURLSessionDataTask *)getNewsDetail:(void (^)(BOOL result,BlackBoardDetail *model,NSError *error))block withBlackboardId:(NSInteger)blackboardId withPageNumber:(NSInteger)pageNumber withPageSize:(NSInteger)pageSize{
    NSDictionary * dict = @{@"token": [DSFUserInfo shareUserInstance].token, @"clazzId":@([DSFUserInfo shareUserInstance].clazz_user.clazz.id),@"blackboardId":@(blackboardId),@"pageNumber":@(0),@"pageSize":@(5)};
    return [[AFAppDotNetAPIClient httpSharedClient] POST:@"blackboard/getNewsDetail" parameters:dict success:^(NSURLSessionDataTask * __unused task, id JSON) {
        NSLog(@"%@",task.originalRequest);
        NSDictionary *response = [JSON valueForKeyPath:@"data"];
        long code = [[JSON valueForKeyPath:@"code"] integerValue];
        BOOL result;
        NSMutableArray *commentListArray=[[NSMutableArray alloc]initWithCapacity:0];
        NSMutableArray *readerListArray=[[NSMutableArray alloc]initWithCapacity:0];
        BlackBoardDetail *model = nil;
        if (code == 10000) {
            result = YES;
            NSError *error;
            model = [[BlackBoardDetail alloc]initWithDictionary:response error:&error];
            for (NSDictionary *dict in [response valueForKeyPath:@"comments"]) {
                CommentListModel *comentModel=[[CommentListModel alloc]initWithDictionary:dict error:&error];
                [commentListArray addObject:comentModel];
            }
            for (NSDictionary *dict in [response valueForKeyPath:@"readers"]) {
                ReaderListModel *readerModel=[[ReaderListModel alloc]initWithDictionary:dict error:&error];
                
                [readerListArray addObject:readerModel];
            }
            model.readers=[NSArray arrayWithArray:readerListArray];
            model.comments=[NSArray arrayWithArray:commentListArray];
            
        }else
            result = NO;
        
        
        if (block) {
            block(result,model,nil);
        }
    } failure:^(NSURLSessionDataTask *__unused task, NSError *error) {
        if (block) {
            block(NO,nil,error);
        }
    }];
}

+ (NSURLSessionDataTask *)getClazzCharts:(void (^)(BOOL result,NSMutableArray *roomList, NSError *error))block withToken:(NSString *)token andClassId:(NSInteger) classId{
    NSDictionary * dict = @{@"token":token,@"clazzId":@(classId)};
    return [[AFAppDotNetAPIClient httpSharedClient] POST:@"chart/getClazzCharts" parameters:dict success:^(NSURLSessionDataTask * __unused task, id JSON) {
        NSLog(@"%@",task.originalRequest);
        NSArray *responseArray = [JSON valueForKeyPath:@"data"];
        NSMutableArray *array = [[NSMutableArray alloc]initWithCapacity:0];
        long code = [[JSON valueForKeyPath:@"code"] integerValue];
        BOOL result;
        if (code == 10000) {
            result = YES;
            for (NSDictionary * dic in responseArray) {
                NewsListModel *room = [[NewsListModel alloc] initWithDictionary:dic error:nil];
                [array addObject:room];
            }
        }else
            result = NO;
        
        if (block) {
            block(result,array,nil);
        }
    } failure:^(NSURLSessionDataTask *__unused task, NSError *error) {
        if (block) {
            block(NO,nil,error);
        }
    }];
}

+ (NSURLSessionDataTask *)getChartDetail:(void (^)(BOOL result,ChartDetail *model,NSError *error))block withChartId:(NSInteger)chartId{
    NSDictionary * dict = @{@"token": [DSFUserInfo shareUserInstance].token, @"clazzId":@([DSFUserInfo shareUserInstance].clazz_user.clazz.id),@"chartId":@(chartId)};
    return [[AFAppDotNetAPIClient httpSharedClient] POST:@"chart/getChartDetail" parameters:dict success:^(NSURLSessionDataTask * __unused task, id JSON) {
        NSLog(@"%@",task.originalRequest);
        NSDictionary *response = [JSON valueForKeyPath:@"data"];
        NSMutableArray *userArr = [[NSMutableArray alloc]initWithCapacity:0];
        NSMutableArray *msgArr = [[NSMutableArray alloc]initWithCapacity:0];
        long code = [[JSON valueForKeyPath:@"code"] integerValue];
        BOOL result;
        ChartDetail *detailModel = nil;
        if (code == 10000) {
            result = YES;
            detailModel = [[ChartDetail alloc] initWithDictionary:response error:nil];
            
            NSArray *array1 = [NSArray arrayWithArray:[response objectForKey:@"chart_users"]];
            NSArray *array2 = [NSArray arrayWithArray:[response objectForKey:@"messages"]];
            
            for (NSDictionary *dic in array1) {
                ChartUser *user = [[ChartUser alloc]initWithDictionary:dic error:nil];
                [userArr addObject:user];
            }
            
            for (NSDictionary *dic in array2) {
                TalkMessage *msg = [[TalkMessage alloc]initWithDictionary:dic error:nil];
                [msgArr addObject:msg];
            }
            
            detailModel.chart_users = userArr;
            detailModel.messages = msgArr;
        }else
            result = NO;
        
        if (block) {
            block(result,detailModel,nil);
        }
    } failure:^(NSURLSessionDataTask *__unused task, NSError *error) {
        if (block) {
            block(NO,nil,error);
        }
    }];
}

+ (NSURLSessionDataTask *)getMessages:(void (^)(BOOL result,NSArray *msgList,NSError *error))block withChartId:(NSInteger)chartId{
    NSDictionary * dict = @{@"token": [DSFUserInfo shareUserInstance].token, @"clazzId":@([DSFUserInfo shareUserInstance].clazz_user.clazz.id),@"chartId":@(chartId)};
    return [[AFAppDotNetAPIClient httpSharedClient] POST:@"message/getMessages" parameters:dict success:^(NSURLSessionDataTask * __unused task, id JSON) {
        NSLog(@"%@",task.originalRequest);
        NSArray *response = [JSON valueForKeyPath:@"data"];
        NSMutableArray *msgArr = [[NSMutableArray alloc]initWithCapacity:0];
        long code = [[JSON valueForKeyPath:@"code"] integerValue];
        BOOL result;
        if (code == 10000) {
            result = YES;
            
            for (NSDictionary *dic in response) {
                TalkMessage *msg = [[TalkMessage alloc]initWithDictionary:dic error:nil];
                [msgArr addObject:msg];
            }
        }else
            result = NO;
        
        if (block) {
            block(result,msgArr,nil);
        }
    } failure:^(NSURLSessionDataTask *__unused task, NSError *error) {
        if (block) {
            block(NO,nil,error);
        }
    }];
}


+ (NSURLSessionDataTask *)leaveApply:(void (^)(BOOL result,NSString *failMessage,NSError *error))block withType:(NSInteger)type withTitle:(NSString *)title withContent:(NSString *)content{
    
    NSDictionary * dict = @{@"token": [DSFUserInfo shareUserInstance].token, @"clazzId":@([DSFUserInfo shareUserInstance].clazz_user.clazz.id),@"type":@(type),@"title":title,@"content":content};
    return [[AFAppDotNetAPIClient httpSharedClient] POST:@"leave/apply" parameters:dict success:^(NSURLSessionDataTask * __unused task, id JSON) {
        NSLog(@"%@",task.originalRequest);
//        NSDictionary *response = [JSON valueForKeyPath:@"data"];
        long code = [[JSON valueForKeyPath:@"code"] integerValue];
        NSString *failMessage = nil;
        BOOL result;
        
        if (code == 10000) {
            result = YES;
        }else{
            result = NO;
            failMessage = [JSON valueForKeyPath:@"describe"];
        }
        
        if (block) {
            block(result,failMessage,nil);
        }
    } failure:^(NSURLSessionDataTask *__unused task, NSError *error) {
        if (block) {
            block(NO,nil,error);
        }
    }];
}

+ (NSURLSessionDataTask *)getComments:(void (^)(BOOL result,NSArray *array,NSError *error))block withBlackboardId:(NSInteger)blackboardId withPageNumber:(NSInteger)pageNumber withPageSize:(NSInteger)pageSize{
    NSDictionary * dict = @{@"token": [DSFUserInfo shareUserInstance].token,@"blackboardId":@(blackboardId),@"pageNumber":@(pageNumber),@"pageSize":@(pageSize)};
    return [[AFAppDotNetAPIClient httpSharedClient] POST:@"blackboard/getComments" parameters:dict success:^(NSURLSessionDataTask * __unused task, id JSON) {
        NSLog(@"%@",task.originalRequest);
        NSArray *response = [JSON valueForKeyPath:@"data"];
        //        NSMutableArray *mutableArr = [[NSMutableArray alloc]initWithCapacity:0];
        NSMutableArray *msgArr = [[NSMutableArray alloc]initWithCapacity:0];
        long code = [[JSON valueForKeyPath:@"code"] integerValue];
        BOOL result;
        if (code == 10000) {
            result = YES;
            for (NSDictionary *dic in response) {
                ContentModel *msg = [[ContentModel alloc]initWithDictionary:dic error:nil];
                [msgArr addObject:msg];
            }
            
        }else
            result = NO;
        
        
        if (block) {
            block(result,msgArr,nil);
        }
    } failure:^(NSURLSessionDataTask *__unused task, NSError *error) {
        if (block) {
            block(NO,nil,error);
        }
    }];
}

+ (AFHTTPRequestOperation *)uploadImage:(void (^)(BOOL result,NSMutableArray *imageUrlList, NSError *error))block withImage:(NSArray *)imageArray andType:(NSInteger)type{
    NSDictionary * dict = @{@"type": @(type)};
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    return [manager POST:@"http://101.200.233.24:8080/jxt-server/picture/upload" parameters:dict constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        for(NSInteger i = 0; i < imageArray.count; i++)
        {
            UIImage * image = [imageArray objectAtIndex:i];
            // 上传的参数名
            NSData *imageData = UIImageJPEGRepresentation(image, 1);
            
            NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
            formatter.dateFormat = @"yyyyMMddHHmmss";
            NSString *str = [formatter stringFromDate:[NSDate date]];
            NSString *fileName = [NSString stringWithFormat:@"%@.jpg", str];
            NSString *picName = [NSString stringWithFormat:@"picture%ld",i+1];
            
            [formData appendPartWithFileData:imageData name:picName fileName:fileName mimeType:@"image/jpeg"];
        }
        
        // 上传图片，以文件流的格式
    } success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"成功");
        NSArray *response = [[responseObject valueForKeyPath:@"data"] valueForKeyPath:@"pictures"];
        NSMutableArray *imageUrlArray = [[NSMutableArray alloc]initWithCapacity:0];
        long code = [[responseObject valueForKeyPath:@"code"] integerValue];
        BOOL result;
        if (code == 10000) {
            result = YES;
            for (NSString *dic in response) {
                [imageUrlArray addObject:dic];
            }
        }else{
            result = NO;
            NSString *failmessage = [responseObject objectForKey:@"describe"];
            NSLog(@"%@",failmessage);
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:failmessage message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];
        }
        if (block) {
            block(result,imageUrlArray,nil);
        }
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"错误 %@", error.localizedDescription);
        if (block) {
            block(NO,nil,nil);
        }
    }];
}
//
//+ (AFHTTPRequestOperation *)uploadIcon:(void (^)(BOOL result,NSString *imageUrl, NSError *error))block withImage:(UIImage *)image{
//    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
//     manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
//    NSDictionary * dict = nil;
//    return [manager POST:@"http://101.200.233.24:8080/jxt-server/user/uploadIcon" parameters:dict constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
//        // 上传的参数名
//        NSData *imageData = UIImageJPEGRepresentation(image, 1);
//        
//        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
//        formatter.dateFormat = @"yyyyMMddHHmmss";
//        NSString *str = [formatter stringFromDate:[NSDate date]];
//        NSString *fileName = [NSString stringWithFormat:@"%@.jpg", str];
//        
//        [formData appendPartWithFileData:imageData name:@"icon" fileName:fileName mimeType:@"image/jpeg"];
//        // 上传图片，以文件流的格式
//    } success:^(AFHTTPRequestOperation *operation, id responseObject) {
//        
//        NSLog(@"成功");
//        
//        NSString *response = [responseObject valueForKeyPath:@"describe"];
//        long code = [[responseObject valueForKeyPath:@"code"] integerValue];
//        BOOL result;
//        if (code == 10000) {
//            result = YES;
//        }else{
//            result = NO;
//            NSString *failmessage = [responseObject objectForKey:@"describe"];
//            NSLog(@"%@",failmessage);
//            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:failmessage message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
//            [alert show];
//        }
//        
//        if (block) {
//            block(result,response,nil);
//        }
//        
//    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//        NSLog(@"错误 %@", error.localizedDescription);
//        if (block) {
//            block(NO,nil,nil);
//        }
//    }];
//}

+ (NSURLSessionDataTask *)createNews:(void (^)(BOOL result,NSString *failMessage,NSError *error))block withType:(NSInteger)type withTitle:(NSString *)title withContent:(NSString *)content withIsTop:(NSInteger)isTop withImages:(NSArray *)images withVisibleRange:(NSInteger)visibleRange withIsAllowComment:(NSInteger)isAllowComment withStudentId:(NSInteger)studentId withRegistrationMode:(NSInteger)registrationMode withUsers:(NSString *)users{
    NSDictionary * dict = @{@"token": [DSFUserInfo shareUserInstance].token, @"clazzId":@([DSFUserInfo shareUserInstance].clazz_user.clazz.id),@"type":@(type),@"title":title,@"content":content,@"isTop":@(isTop),@"visibleRange":@(visibleRange),@"isAllowComment":@(isAllowComment),@"studentId":@(studentId),@"registrationMode":@(registrationMode)};
    
    NSMutableString *imageUrl = [NSMutableString stringWithFormat:@"["];
    for (int i = 0; i < images.count ;i++) {
        if (i==0)
        {
            [imageUrl appendString:[NSString stringWithFormat:@"\"%@\"",images[i]]];
        }
        else
        {
            [imageUrl appendString:[NSString stringWithFormat:@",\"%@\"",images[i]]];
        }
    }
    [imageUrl appendString:@"]"];
    
    NSMutableDictionary *temp = [[NSMutableDictionary alloc] initWithDictionary:dict];
    if (images.count) {
        [temp setObject:imageUrl forKey:@"images"];
    }
    
    return [[AFAppDotNetAPIClient httpSharedClient] POST:@"blackboard/createNews" parameters:temp success:^(NSURLSessionDataTask * __unused task, id JSON) {
        NSLog(@"%@",task.originalRequest);
        //        NSDictionary *response = [JSON valueForKeyPath:@"data"];
        long code = [[JSON valueForKeyPath:@"code"] integerValue];
        NSString *failMessage = nil;
        BOOL result;
        
        if (code == 10000) {
            result = YES;
        }else{
            result = NO;
            failMessage = [JSON valueForKeyPath:@"describe"];
        }
        
        if (block) {
            block(result,failMessage,nil);
        }
    } failure:^(NSURLSessionDataTask *__unused task, NSError *error) {
        if (block) {
            block(NO,nil,error);
        }
    }];
}


+ (NSURLSessionDataTask *)comment:(void (^)(BOOL result,NSError *error))block withBlackboardId:(NSInteger)blackboardId withReceiverId:(NSInteger)receiverId withContent:(NSString *)content{
    NSDictionary * dict = @{@"token": [DSFUserInfo shareUserInstance].token, @"blackboardId":@(blackboardId),@"content":content};
    
    NSMutableDictionary *temp = [[NSMutableDictionary alloc]initWithDictionary:dict];
    if (receiverId) {
        [temp setObject:@(receiverId) forKey:@"receiverId"];
    }
    
    return [[AFAppDotNetAPIClient httpSharedClient] POST:@"blackboard/comment" parameters:temp success:^(NSURLSessionDataTask * __unused task, id JSON) {
        NSLog(@"%@",task.originalRequest);
        //        NSDictionary *response = [JSON valueForKeyPath:@"data"];
        long code = [[JSON valueForKeyPath:@"code"] integerValue];
        NSString *failMessage = nil;
        BOOL result;
        
        if (code == 10000) {
            result = YES;
        }else{
            result = NO;
            failMessage = [JSON valueForKeyPath:@"describe"];
            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:failMessage message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alertView show];
        }
        
        if (block) {
            block(result,nil);
        }
    } failure:^(NSURLSessionDataTask *__unused task, NSError *error) {
        if (block) {
            block(NO,error);
        }
    }];
}

+ (NSURLSessionDataTask *)getLeaves:(void (^)(BOOL result,NSArray *leavesArray,NSError *error))block{
    NSDictionary * dict = @{@"token": [DSFUserInfo shareUserInstance].token, @"clazzId":@([DSFUserInfo shareUserInstance].clazz_user.clazz.id)};
    
    return [[AFAppDotNetAPIClient httpSharedClient] POST:@"leave/getLeaves" parameters:dict success:^(NSURLSessionDataTask * __unused task, id JSON) {
        NSString *failMessage = nil;
        NSLog(@"%@",task.originalRequest);
        NSArray *responseArray = [JSON valueForKeyPath:@"data"];
        NSMutableArray *array = [[NSMutableArray alloc]initWithCapacity:0];
        long code = [[JSON valueForKeyPath:@"code"] integerValue];
        BOOL result;
        if (code == 10000) {
            result = YES;
            for (NSDictionary * dic in responseArray) {
                NewsListModel *room = [[NewsListModel alloc] initWithDictionary:dic error:nil];
                [array addObject:room];
            }
        }else{
            result = NO;
            failMessage = [JSON valueForKeyPath:@"describe"];
            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:failMessage message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alertView show];
        }
        
        if (block) {
            block(result,array,nil);
        }
    } failure:^(NSURLSessionDataTask *__unused task, NSError *error) {
        if (block) {
            block(NO,nil,error);
        }
    }];
}

+ (NSURLSessionDataTask *)modifyRelation:(void (^)(BOOL result,NSError *error))block withBlackboardId:(NSInteger)blackboardId withType:(NSInteger)type withStatus:(NSInteger)status{
    NSDictionary * dict = @{@"token": [DSFUserInfo shareUserInstance].token, @"blackboardId":@(blackboardId),@"type":@(type),@"status":@(status)};
    
    return [[AFAppDotNetAPIClient httpSharedClient] POST:@"blackboard/modifyRelation" parameters:dict success:^(NSURLSessionDataTask * __unused task, id JSON) {
        NSString *failMessage = nil;
        NSLog(@"%@",task.originalRequest);
        long code = [[JSON valueForKeyPath:@"code"] integerValue];
        BOOL result;
        if (code == 10000) {
            result = YES;
        }else{
            result = NO;
            failMessage = [JSON valueForKeyPath:@"describe"];
            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:failMessage message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alertView show];
        }
        
        if (block) {
            block(result,nil);
        }
    } failure:^(NSURLSessionDataTask *__unused task, NSError *error) {
        if (block) {
            block(NO,error);
        }
    }];

}

+ (NSURLSessionDataTask *)getClazzStudents:(void (^)(BOOL result,NSMutableArray *roomList, NSError *error))block withToken:(NSString *)token andClassId:(NSInteger) classId{
    NSDictionary * dict = @{@"token":token,@"clazzId":@(classId)};
    return [[AFAppDotNetAPIClient httpSharedClient] POST:@"clazz/getClazzStudents" parameters:dict success:^(NSURLSessionDataTask * __unused task, id JSON) {
//        NSLog(@"%@",task.originalRequest);
        NSArray *responseArray = [JSON valueForKeyPath:@"data"];
        NSMutableArray *array = [[NSMutableArray alloc]initWithCapacity:0];
        long code = [[JSON valueForKeyPath:@"code"] integerValue];
        BOOL result;
        if (code == 10000) {
            result = YES;
            for (NSDictionary * dic in responseArray) {
                ClazzStudents *room = [[ClazzStudents alloc] initWithDictionary:dic error:nil];
                [array addObject:room];
            }
        }else
            result = NO;
        
        if (block) {
            block(result,array,nil);
        }
    } failure:^(NSURLSessionDataTask *__unused task, NSError *error) {
        if (block) {
            block(NO,nil,error);
        }
    }];
}
/**
 *  11)	获取聊天室成员信息
 *
 *  @param block   <#block description#>
 *  @param token   登录令牌
 *  @param chartId 聊天室Id
 *
 *  @return <#return value description#>
 */
+ (NSURLSessionDataTask *)getChartUsers:(void (^)(BOOL result,NSMutableArray *roomList, NSError *error))block withToken:(NSString *)token andChartId:(NSInteger) chartId
{
    NSDictionary * dict = @{@"token":token,@"chartId":@(chartId)};
    return [[AFAppDotNetAPIClient httpSharedClient] GET:@"chart/getChartUsers" parameters:dict success:^(NSURLSessionDataTask * __unused task, id JSON) {
        NSArray *responseArray = [JSON valueForKeyPath:@"data"];
        NSMutableArray *array = [[NSMutableArray alloc]initWithCapacity:0];
        long code = [[JSON valueForKeyPath:@"code"] integerValue];
        BOOL result;
        if (code == 10000) {
            result = YES;
            for (NSDictionary * dic in responseArray) {
                ChartUser *room = [[ChartUser alloc] initWithDictionary:dic error:nil];
                [array addObject:room];
            }
        }else
            result = NO;
        
        if (block) {
            block(result,array,nil);
        }
    } failure:^(NSURLSessionDataTask *__unused task, NSError *error) {
        if (block) {
            block(NO,nil,error);
        }
    }];
}
+ (NSURLSessionDataTask *)getWristbands:(void (^)(BOOL result,NSMutableArray *wristbands, NSError *error))block{
    NSDictionary * dict = @{@"token":[DSFUserInfo shareUserInstance].token,@"clazzId":@([DSFUserInfo shareUserInstance].clazz_user.clazz.id)};
    return [[AFAppDotNetAPIClient httpSharedClient] POST:@"wristband/getWristbands" parameters:dict success:^(NSURLSessionDataTask * __unused task, id JSON) {
        //        NSLog(@"%@",task.originalRequest);
        NSArray *responseArray = [JSON valueForKeyPath:@"data"];
        NSMutableArray *array = [[NSMutableArray alloc]initWithCapacity:0];
        long code = [[JSON valueForKeyPath:@"code"] integerValue];
        BOOL result;
        if (code == 10000) {
            result = YES;
            for (NSDictionary * dic in responseArray) {
                Wristbands *room = [[Wristbands alloc] initWithDictionary:dic error:nil];
                [array addObject:room];
            }
        }else
            result = NO;
        
        if (block) {
            block(result,array,nil);
        }
    } failure:^(NSURLSessionDataTask *__unused task, NSError *error) {
        if (block) {
            block(NO,nil,error);
        }
    }];
}

+ (NSURLSessionDataTask *)getPayments:(void (^)(BOOL result,NSMutableArray *payments, NSError *error))block andPageNumber:(NSInteger)pageNumber andPageSize:(NSInteger)pageSize{
    NSDictionary * dict = @{@"token":[DSFUserInfo shareUserInstance].token,@"clazzId":@([DSFUserInfo shareUserInstance].clazz_user.clazz.id),@"pangeNumber":@(pageNumber),@"pageSize":@(pageSize)};
    return [[AFAppDotNetAPIClient httpSharedClient] POST:@"payment/getPayments" parameters:dict success:^(NSURLSessionDataTask * __unused task, id JSON) {
        //        NSLog(@"%@",task.originalRequest);
        NSArray *responseArray = [JSON valueForKeyPath:@"data"];
        NSMutableArray *array = [[NSMutableArray alloc]initWithCapacity:0];
        long code = [[JSON valueForKeyPath:@"code"] integerValue];
        BOOL result;
        if (code == 10000) {
            result = YES;
            for (NSDictionary * dic in responseArray) {
                Payments *room = [[Payments alloc] initWithDictionary:dic error:nil];
                [array addObject:room];
            }
        }else
            result = NO;
        
        if (block) {
            block(result,array,nil);
        }
    } failure:^(NSURLSessionDataTask *__unused task, NSError *error) {
        if (block) {
            block(NO,nil,error);
        }
    }];
}

+ (NSURLSessionDataTask *)getPaymentDetail:(void (^)(BOOL result,PaymentDetail *paymentDetail, NSError *error))block andPaymentId:(NSInteger)paymentId{
    NSDictionary * dict = @{@"token":[DSFUserInfo shareUserInstance].token,@"paymentId":@(paymentId)};
    return [[AFAppDotNetAPIClient httpSharedClient] POST:@"payment/getPaymentDetail" parameters:dict success:^(NSURLSessionDataTask * __unused task, id JSON) {
        //        NSLog(@"%@",task.originalRequest);
        NSDictionary *responseArray = [JSON valueForKeyPath:@"data"];
//        NSMutableArray *array = [[NSMutableArray alloc]initWithCapacity:0];
        PaymentDetail *model = nil;
        long code = [[JSON valueForKeyPath:@"code"] integerValue];
        BOOL result;
        if (code == 10000) {
            result = YES;
            model = [[PaymentDetail alloc] initWithDictionary:responseArray error:nil];
        }else
            result = NO;
        
        if (block) {
            block(result,model,nil);
        }
    } failure:^(NSURLSessionDataTask *__unused task, NSError *error) {
        if (block) {
            block(NO,nil,error);
        }
    }];
}

+ (NSURLSessionDataTask *)modify:(void (^)(BOOL result,NSString *failMessage,NSError *error))block withIcon:(NSString *)icon andPushId:(NSString *)pushId{
    NSDictionary * dict = @{@"token":[DSFUserInfo shareUserInstance].token};
    NSMutableDictionary *temp = [[NSMutableDictionary alloc]initWithDictionary:dict];
    if (icon) {
        [temp setObject:icon forKey:@"icon"];
    }
    if (pushId) {
        [temp setObject:pushId forKey:@"pushId"];
    }
    return [[AFAppDotNetAPIClient httpSharedClient] POST:@"user/modify" parameters:temp success:^(NSURLSessionDataTask * __unused task, id JSON) {
        NSLog(@"%@",task.originalRequest);
        NSString *message = nil;
        long code = [[JSON valueForKeyPath:@"code"] integerValue];
        BOOL result;
        if (code == 10000) {
            result = YES;
        }else{
            result = NO;
            message = [JSON valueForKeyPath:@"describe"];
        }
        if (block) {
            block(result,nil,nil);
        }
    } failure:^(NSURLSessionDataTask *__unused task, NSError *error) {
        if (block) {
            block(NO,nil,error);
        }
    }];
}



@end

@implementation BlackBoardModel

@end

@implementation BlackBoardDetail

@end
@implementation CommentListModel

@end

@implementation ReaderListModel

@end

@implementation NewsListModel

@end

@implementation ChartDetail

@end

@implementation TalkMessage

@end

@implementation ChartUser

@end

@implementation ContentModel

@end

@implementation ClazzStudents

@end

@implementation Wristbands

@end

@implementation Payments

@end

@implementation PaymentDetail

@end